package com.huizu.goods.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.huizu.common.annotation.Log;
import com.huizu.common.enums.BusinessType;
import com.huizu.goods.domain.ShopCoupon;
import com.huizu.goods.service.IShopCouponService;
import com.huizu.common.core.controller.BaseController;
import com.huizu.common.core.domain.AjaxResult;
import com.huizu.common.utils.ShiroUtils;
import com.huizu.common.utils.poi.ExcelUtil;
import com.huizu.common.core.page.TableDataInfo;

/**
 * 优惠卷管理Controller
 * 
 * @author huizu
 * @date 2022-02-10
 */
@Controller
@RequestMapping("/shop/coupon")
public class ShopCouponController extends BaseController {
	private String prefix = "shop/coupon";

	@Autowired
	private IShopCouponService shopCouponService;

	@RequiresPermissions("shop:coupon:view")
	@GetMapping()
	public String coupon() {

		return prefix + "/coupon";
	}

	/**
	 * 查询优惠卷管理列表
	 */
	@RequiresPermissions("shop:coupon:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ShopCoupon shopCoupon) {
		startPage();
		List<ShopCoupon> list = shopCouponService.selectShopCouponList(shopCoupon);
		return getDataTable(list);
	}

	/**
	 * 导出优惠卷管理列表
	 */
	@RequiresPermissions("shop:coupon:export")
	@Log(title = "优惠卷管理", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(ShopCoupon shopCoupon) {
		List<ShopCoupon> list = shopCouponService.selectShopCouponList(shopCoupon);
		ExcelUtil<ShopCoupon> util = new ExcelUtil<ShopCoupon>(ShopCoupon.class);
		return util.exportExcel(list, "优惠卷管理数据");
	}

	/**
	 * 新增优惠卷管理
	 */
	@GetMapping("/add")
	public String add(ModelMap mmap) {
		mmap.put("shopId", ShiroUtils.getSysUser().getShopId());
		return prefix + "/add";
	}

	/**
	 * 新增保存优惠卷管理
	 */
	@RequiresPermissions("shop:coupon:add")
	@Log(title = "优惠卷管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ShopCoupon shopCoupon) {
		return toAjax(shopCouponService.insertShopCoupon(shopCoupon));
	}

	/**
	 * 修改优惠卷管理
	 */
	@RequiresPermissions("shop:coupon:edit")
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		ShopCoupon shopCoupon = shopCouponService.selectShopCouponById(id);
		mmap.put("shopCoupon", shopCoupon);
		return prefix + "/edit";
	}

	/**
	 * 修改保存优惠卷管理
	 */
	@RequiresPermissions("shop:coupon:edit")
	@Log(title = "优惠卷管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ShopCoupon shopCoupon) {
		return toAjax(shopCouponService.updateShopCoupon(shopCoupon));
	}

	/**
	 * 删除优惠卷管理
	 */
	@RequiresPermissions("shop:coupon:remove")
	@Log(title = "优惠卷管理", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(shopCouponService.deleteShopCouponByIds(ids));
	}
}
